package com.giser.testapp.lib.App;

import android.app.Application;
import android.content.Context;
import android.location.Location;
import android.os.Build;
import android.os.StrictMode;

import com.giser.testapp.lib.Location.GeographicLocation;
import com.giser.testapp.lib.Location.LocationServer;
import com.giser.testapp.lib.Tool.EnvLog;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by Lss on 2017/11/29.
 */

public class EnvApplication extends Application {
    private static EnvApplication application;
    //private static LocationInfo locationInfo;
    private LocationServer locationServer;

    public int powerMb=0;

    public Location lastLocation = null;

    public GeographicLocation geographicLocation=null;
    public int locationModuleTag=0;
    public int firstChangeModue=0;
    public Context minContext=null;

    public int userID=0;
    public int powerValue=0;
    @Override
    public void onCreate() {
        // 初始化单例对象
        application = this;
        super.onCreate();
        JPushInterface.setDebugMode(true); 	// 设置开启日志,发布时请关闭日志
        JPushInterface.init(this);     		// 初始化 JPush

        // 置入一个不设防的VmPolicy（不设置的话 7.0以上一调用拍照功能就崩溃了）
        // 还有一种方式：manifest中加入provider然后修改intent代码
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
        }
    }


    /**
     * EnvApplication实例
     */
    public static EnvApplication getApplication() {
        if (application == null) {
            throw new RuntimeException("Application not created !");
        }
        return application;
    }
    public LocationServer getLocationServer(Context mContext){
        if(locationServer==null){
            locationServer=new LocationServer(mContext);
        }
        return locationServer;
    }
    public void startLocationServer(Context mContext){
        EnvLog.i("startLocationServer.....");
        getLocationServer(mContext).start();
    }
    /*public static LocationInfo getLocationInfo(Context mContext){
        if(locationInfo==null){
            locationInfo=new LocationInfo(mContext);
        }
        return locationInfo;
    }*/
    public void Exit(){
        System.exit(0);
    }
}
